/**
 * 用户服务 用来获取ajax数据
 */
app.service('pcdService', function ($http, $q) {

   
    this.citylist = function(){
    	var baseUrl = 'libs/city.json';
	    var service = {};
	    var city = new baseService($http, $q, baseUrl);
	    return city;
    }
    
    this.prolist = function(){
    	var baseUrl = 'libs/province.json';
	    var service = {};
	    var city = new baseService($http, $q, baseUrl);
	    return city;
    }
    
    this.dislist = function(){
    	var baseUrl = 'libs/district.json';
	    var service = {};
	    var city = new baseService($http, $q, baseUrl);
	    return city;
    }
    
    
})

/* //获取用户列表信息
 service.list = function(obj) {
 var q = $q.defer();
 $http.get(baseUrl+'/users/list',{params:obj}).then(function(e) {
 var data=e.data;//数据过滤
 q.resolve(data);
 },function(err) {
 q.reject(err);//错误应该处理一下
 })
 return q.promise;
 }*/

/*   service.getById = function(obj) {
 var q = $q.defer();
 $http.get(baseUrl+'/users/getById',{params:obj}).then(function(e) {
 var data=e.data;//数据过滤
 q.resolve(data);
 },function(err) {
 q.reject(err);//错误应该处理一下
 })
 return q.promise;
 }*/

app.factory('myHttp', function ($http, $q){  
    var factory = {};  
    factory.loadData = function(arges) {  
        var defer = $q.defer();  
        if (arges.method == 'GET') {  
            $http({  
                url: arges.url,  
                method: arges.method,  
                params: arges.params,
                dataType: 'json'
            }).success(function (data) {  
                defer.resolve(data);  
            }).  
            error(function (data, status, headers, config) {  
                // defer.resolve(data);  
                defer.reject(data);  
            });  
        } else {  
            $http({  
                url: arges.url,  
                method: arges.method,  
                params: arges.params,
                dataType: 'json'
            }).success(function (data) {  
                defer.resolve(data);  
            }).  
            error(function (data, status, headers, config) {  
                // defer.resolve(data);  
                defer.reject(data);  
            });  
        }  
        return defer.promise;  
        };  
    return factory;  
});



